//打开注册页面
function register() {
	
	window.location.href = ctx+"/login/register";
	
}

//完成注册页面
function addRegister() {
	if(!$( "#registerForm" ).validate({
		rules: {
			username:{required:true,
		        remote:{                                          //验证用户名是否存在
		               type:"POST",
		               url:ctx+"/login/remoteUsername",             //servlet
		               cache:false,
		               async:false,
		               data:{
		            	   username:function(){
		                	 return $("#username").val();
		                 }
		               }
		              } 
		            },
			password: "required",
			password2: {
				required: true,
		      	equalTo: "#password"
		  	},
		  	studentName: "required"
		},
		messages: {
			username: {
		        required: "<font color='red'>请输入用户名</font>",
		        remote: "<font color='red'>用户名已存在</font>"
		    },
			password: "<font color='red'>请输入密码</font>",
			password2: {
		        required: "<font color='red'>请再次输入新密码</font>",
		        equalTo: "<font color='red'>两次密码输入不一致</font>"
		    },
		    studentName: "<font color='red'>请输入学生姓名</font>",
	      }
	}).form()) return false;
	
	$.ajax({
        type: "POST",
        url: ctx+"/login/addRegister",
        data: $("#registerForm").serialize(),
        dataType: "json",
        success: function(data){
        	if(data.statusCode==1){
        		alert("注册成功");
        		window.location.href = ctx;
        	}else{
        		alert(data.message)
        	}
        }
    });
}


